<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb>
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card>
      <el-row>
        <!-- input搜索框 -->
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="input3">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 列表 -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template slot-scope="scope">
            <el-tag type="sucess" v-if="scope.row.pay_status==='1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间" prop="create_time">
          <template slot-scope='scope'>
            {{scope.row.create_time |dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="showBox"></el-button>
            <el-button
              type="success"
              icon="el-icon-location-outline"
              size="mini"
              @click="showProgess"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>

    <!-- 添加地址对话框 -->
    <el-dialog title="修改地址" :visible.sync="orderDialogVisible" width="50%">
      <!-- 主内容 -->
      <el-form label-width="80px">
        <el-form-item label="省市区/县">
          <el-input></el-input>
        </el-form-item>
        <el-form-item label="详细地址">
          <el-input></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="orderDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="orderDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="物流进度" :visible.sync="progessDialogVisible" width="50%">
      <!-- 时间线 -->
      <el-timeline >
        <el-timeline-item
          v-for="(activity, index) in progessInfo"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>

      <span slot="footer" class="dialog-footer">
        <el-button @click="progessDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="progessDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      input3: '',
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      // 总数
      total: 0,
      // 商品列表数据
      orderList: [],
      //修改地址的显示隐藏
      orderDialogVisible: false,
      //物流进度的显示隐藏
      progessDialogVisible: false,
      //进度状态数据
      progessInfo: []
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    async getOrderList() {
      let { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      console.log(res)
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg)
      }
      this.total = res.data.total
      this.orderList = res.data.goods
    },
    // 分页页数改变
    handleSizeChange(val) {
      console.log(val)
      this.queryInfo.pagesize = val
      this.getOrderList()
    },
    //分页第几页
    handleCurrentChange(val) {
      console.log(val)
      this.queryInfo.pagenum = val
      this.getOrderList()
    },
    //修改地址对话框
    showBox() {
      this.orderDialogVisible = true
    },
    //物流进度对话框
    showProgess() {
      this.$http
        .get('/kuaidi/1106975712662')
        .then(res => {
          this.progessInfo = res.data.data
        })
        .catch(err => {
          console.log(err)
        })
      this.progessDialogVisible = true
    }
  }
}
</script>
<style lang="less" scoped>
</style>

